package com.qf.web;

import com.qf.pojo.Dept;
import com.qf.pojo.Emp;
import com.qf.service.DeptService;
import com.qf.service.impl.DeptServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/findDeptAll")
public class FindDeptAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DeptService deptService=new DeptServiceImpl();
        List<Dept> list = deptService.findDeptAll();
        PrintWriter writer = resp.getWriter();
        writer.println("<html>");
        writer.println("<head><title>部门信息</title></head>");
        writer.println("<body border='1px'>");
        writer.println("<table>");
        writer.println("<tr>");
        writer.println("<td>id</td>");
        writer.println("<td>dname</td>");
        writer.println("<td>loc</td>");
        writer.println("</tr>");
        for(Dept p:list){
            writer.println("<tr>");
            writer.println("<td>"+p.getId()+"</td>");
            writer.println("<td>"+p.getDname()+"</td>");
            writer.println("<td>"+p.getLoc()+"</td>");
            writer.println("</tr>");
        }
        writer.println("</table>");
        writer.println("</body>");
        writer.println("<html>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
